package com.ykg.controller;

import com.ykg.annotation.PassToken;
import com.ykg.dto.EntrustDTO;
import com.ykg.dto.RunStampDTO;
import com.ykg.dto.StowBeltDTO;
import com.ykg.enums.ResultEnum;
import com.ykg.interceptor.ScopeLevel;
import com.ykg.pojo.Entrust;
import com.ykg.request.CheckEntrustRequest;
import com.ykg.service.IRunStampService;
import com.ykg.service.IStowBeltService;
import com.ykg.util.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 类(接口)：
 * Created on 2021/6/25 10:19.
 * Author: zetong
 * Description:保管队
 */
@Api(tags = "保管队Api")
@RestController
@RequestMapping("/api/custody")
public class CustodyController {
    @Autowired
    private IRunStampService iRunStampService;
    @Autowired
    private IStowBeltService iStowBeltService;

   // @PassToken
    @ApiOperation("获取全部的待跑跺委托单")
    @GetMapping(value = "/all",produces = "application/json")
    @ScopeLevel(value = 8)
    public ResultResponse findAllEntrustNotRun(){
        List<Entrust> entrusts = iRunStampService.getEntrustRun();
        return  new ResultResponse(entrusts);
    }

   // @PassToken
    @ApiOperation("获取跑跺委托单的详情")
    @GetMapping(value = "/{entrustId}",produces = "application/json")
    @ScopeLevel(value = 8)
    public ResultResponse getEntrustNotRunDetailed(@PathVariable(value = "entrustId") String entrustId){
        if(entrustId==null){
            return  new ResultResponse(ResultEnum.PARAM_ERROR);
        }
        EntrustDTO entrustDTO = iRunStampService.getEntrustNotRunDetailed(entrustId);
        if(Objects.isNull(entrustDTO)){
            return new ResultResponse(ResultEnum.FAILURE);
        }
        return new ResultResponse(entrustDTO);
    }

    //@PassToken
    @ApiOperation("自动跑跺")
    @GetMapping(value = "/stow/{entrustId}",produces = "application/json")
    @ScopeLevel(value = 8)
    public ResultResponse startRunStamp(@PathVariable(value = "entrustId") String entrustId){
        if(entrustId==null){
            return  new ResultResponse(ResultEnum.PARAM_ERROR);
        }
        RunStampDTO runStampDTO = iRunStampService.startRunStamp(entrustId);
        if(Objects.isNull(runStampDTO)){
            return new ResultResponse(ResultEnum.FAILURE);
        }
        return new ResultResponse(runStampDTO);
    }


    //@PassToken
    @ApiOperation("完成跑跺")
    @PostMapping(value = "/finishRunStamp")
    @ScopeLevel(value = 8)
    public ResultResponse finishRunStamp(@RequestParam String entrustId){
        if(entrustId == null){
            return  new ResultResponse(ResultEnum.PARAM_ERROR);
        }
        int status = iRunStampService.finishRunStamp(entrustId);
        if(Objects.isNull(status)){
            return  new ResultResponse(ResultEnum.FAILURE);
        }
        return new ResultResponse(ResultEnum.SUCCESS);

    }

}
